Kwik.Page.include("Kwik.Ui.Controls.Control.js");
Kwik.Page.include("Kwik.Ui.Utility.js");

/**
* SWF base object for shockwave flash movies
* @constructor
* @extends Kwik.Ui.Controls.Control
* @requires Kwik.Ui.Controls.Control
* @requires Kwik.Ui.Utility
* @created 10:15 AM 6/22/2009
* @modified 10:15 AM 6/22/2009
*/
Kwik.Ui.Controls.Swf = function(config)
{
	/** @ignore */
	Kwik.Utility.extend(this, "Kwik.Ui.Controls.Control");
	this.__class.push("Kwik.Ui.Controls.Swf");

	/** Reference to a HTMLObject element for swf @type HTMLObject */
	this.swf = null;
	/** Source of the SWF movie @type String */
	this.src = "";
	/** Parameters object, name value pairs which can will be added to the HTMLObject @type Object */
	this.parameters = {};
	/** Flashvars object, name value pairs which can be obtained with the getFlashVars method @type Object */
	this.flashvars = {};

	/** Get the flashvars as string @type String */
	this.getFlashVars = function Swf_getFlashVars()
	{
		var ret = [];
		for(e in this.flashvars)
		{
			if(this.flashvars[e] == Object.prototype[e]){continue;}
			ret.push(e + "=" + this.flashvars[e]);
		}
		var vars = ret.join("&");
		Kwik.Page.log.write("Kwik.Ui.Controls.Swf.getFlashVars: Flashvars from object:'" + vars + "'");
		return vars;
	};

	/** Internal method which appends the HTMLObject to the control's element */
	this._appendSwf = function Swf__appendSwf()
	{
		if(this.swf == null)
		{
			Kwik.Page.log.write("Kwik.Ui.Controls.Swf._appendSwf: A new SWF object has been created.");
			this.parameters.flashvars = this.getFlashVars();
			this.parameters.src = this.src;
			this.swf = Kwik.Ui.Utility.createSwfObject({width: "100%", height: "100%"}, this.parameters);
		}
		this.element.appendChild(this.swf);
	};

	/** Open the SWF object */
	this.open = function Swf_open(parent)
	{
		this.Kwik$Ui$Controls$Control.open(parent);
		this._appendSwf();
	};

	/** Load the SWF object */
	this.load = function Swf_load(element)
	{
		this.Kwik$Ui$Controls$Control.load(element);
		this._appendSwf();
		return null;
	};

	/** Set the flash movie propertie */
	this.setSrc = function Swf_setSrc(src)
	{
		if(this.src === src){return;}
		this.src = src;
		Kwik.Page.log.write("Kwik.Ui.Controls.Swf.setSrc: Setting source to '" + src + "'.");
		if(this.swf != null)
		{
			this.swf.data = src;
			var param1 = Kwik.Dom.Utility.getElementsByAttribute(this.swf, "name", "src")[0];
			var param2 = Kwik.Dom.Utility.getElementsByAttribute(this.swf, "name", "movie")[0];
			if(param1){param1.value = src;}
			if(param2){param2.value = src;}
		}
	};
	
	/** Configure this SWF control @type Object */
	this.configure = function Swf_configure(config)
	{
		Kwik.Page.log.write("Kwik.Ui.Controls.Swf.configure: Setting swf specific items from config.");

		config = this.Kwik$Ui$Controls$Control.configure(config);
		if(Kwik.Type.isObject(config.flashvars))
		{
			for(e in config.flashvars)
				if(config.flashvars != Object.prototype[e])
					this.flashvars[e] = config.flashvars[e];
		}
		if(typeof config.src != "undefined"){this.src = config.src;}
		return config;	
	};


	/** @ignore */
	this.main = function Swf_main(config)
	{
		if(config){this.configure(config);}
	}; this.main(config);
};

/**
* SWF control configuration object
* @constructor
* @created 5:11 PM 6/22/2009
* @modified 5:11 PM 6/22/2009
*/
Kwik.Ui.Controls.SwfConfig = function()
{
	/** Flashvars object @type Object */
	this.flashvars = {};
	/** Swf movie source @type String */
	this.src = "";
};
